/**
 * 
 */
package uy.com.pzit.fpmundialmodel.response;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

import org.apache.log4j.Logger;

import uy.com.pzit.fpmundialmodel.web.ModelContextServlet;

/**
 * @author pferraz
 * 
 */
public class MessageManager {
	private static Logger logger = Logger.getLogger(MessageManager.class);
	public static Properties messages;
	private String filePath;
	private static MessageManager instance;

	public String getMessage(String key) {
		return messages.getProperty(key);
	}

	private void loadMessages() {
		messages = new Properties();
		FileInputStream fIn;
		try {
			fIn = new FileInputStream(new File(filePath));
			messages.load(fIn);
		} catch (FileNotFoundException e) {
			logger.error(e);
		} catch (IOException e) {
			logger.error(e);
		}

	}
	
	public static MessageManager getInstance(){
		if(instance==null){
			instance=(MessageManager) ModelContextServlet.getSpringContext().getBean("messageManager");
			instance.loadMessages();
		}
		return instance;
	}

	/**
	 * @param filePath the filePath to set
	 */
	public void setFilePath(String filePath) {
		this.filePath = filePath;
	}
	
	
}
